﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RMS
{
    public partial class frmDiscountVIPMng : Form
    {
        public frmDiscountVIPMng()
        {
            InitializeComponent();
        }

        private void btnSave2_Click(object sender, EventArgs e)
        {
            string code = System.IO.File.ReadAllText(Constants.VerifyAdminPath);
            var file = new System.IO.StreamWriter(Constants.VerifyAdminPath);
            try
            {
                var arr = code.Split('#');
                file.Write(arr[0] + "#" + numericUpDown1.Text + "#" + arr[2] + "#" + (checkBox1.Checked ? "1" : "0"));
                MessageBox.Show("Lưu thành công.");
            }
            finally
            {
                file.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmDiscountVIPMng_Load(object sender, EventArgs e)
        {
            try
            {
                string verifyCode = System.IO.File.ReadAllText(Constants.VerifyAdminPath);
                var arr = verifyCode.Split('#');
                numericUpDown1.Text = arr[1];
                checkBox1.Checked = arr[3] == "1";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

        private void numericUpDown1_KeyPress(object sender, KeyPressEventArgs e)
        {
            validateNumeric(e);
        }
        private void validateNumeric(KeyPressEventArgs e)
        {
            char key = e.KeyChar;
            if ((key >= 48) && (key <= 58) || (key == 46) || key == 8 || key == 9 || (key >= 37 && key <= 40) ||
            key == 144 || key == ',')
            {
                e.Handled = false;
            }
            else
                e.Handled = true;
        }
    }
}
